<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //es6允许使用=>定义函数
    // let fn = function(){

    // }

    let fn = (a,b) => {
      return a + b
    }
    let result = fn(1,2)
    console.log(result)

    //1 this是静态的 始终指向函数声明时所在作用域this指向的值
    function getName(){
      console.log(this.name)
    }

    let getName2 = () => {
      console.log(this.name)
    }

    window.name = 'atguigu'
    const school = {
      name:'尚硅谷'
    }

    //直接调用
    getName()
    getName2()
    //call方法调用
    getName.call(school)
    getName2.call(school)

    //2 不能作为构造函数去实例化对象
    function Person(name,age){
      this.name = name
      this.age = age
    }
    
    // let Person = (name,age) =>{
    //   this.name = name
    //   this.age = age
    // }
    let me = new Person('tom',18)
    console.log(me)

    //3 不能使用arguments（保存实参）
    // let fn2 = () => {
    //   console.log(arguments)
    // }
    // fn2(1,2,3)

    //4 箭头函数简写
    //省略小括号：只有一个形参
    let add = n => {
      return n + n
    }
    console.log(add(9))
    //省略花括号，当代码体只有一条语句，return必须省略，而且语句的执行结果就是函数的返回值
    let pow = n => n*n
    console.log(pow(9))
  </script>
</body>
</html>